package com.devilvan.betrice.export.component;

import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @author Evad.Wu
 * @Description Easyexcel导出xls 配置类
 * @date 2022-09-07
 */
@Configuration
public class EasyexcelConfig {
    /**
     * 默认表单样式
     *
     * @return {@link HorizontalCellStyleStrategy}
     */
    @Lazy
    @Bean(value = "basicWriteStrategy")
    public HorizontalCellStyleStrategy getBasicWriteStrategy() {
        // 头字体策略
        WriteFont writeHeadFont = new WriteFont();
        writeHeadFont.setFontName("微软雅黑");
        writeHeadFont.setFontHeightInPoints((short) 12);
        writeHeadFont.setBold(false);
        // 头的策略
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        headWriteCellStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex());
        headWriteCellStyle.setWriteFont(writeHeadFont);
        // 内容字体策略
        WriteFont writeContentFont = new WriteFont();
        writeContentFont.setFontName("黑体");
        writeContentFont.setFontHeightInPoints((short) 12);
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        contentWriteCellStyle.setWriteFont(writeContentFont);
        // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
        return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
    }
}
